<template>
  <el-container>
    <el-main>
      <h3 style="text-align: left;padding-left: 5%; ">商户维护页面</h3>
      <el-form :model="ruleForm" label-position="left" label-width="100px" style="margin: 20px">
        <el-form-item label="门店照片 :">
          <el-upload
              class="avatar-uploader"
              action="your_upload_action"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="手机号:" prop="phoneNumber" style="width: 50%;">
          <el-input v-model="ruleForm.merchantInfo.phone"></el-input>
        </el-form-item>
        <el-form-item label="门店名称:" prop="storeName" style="width: 50%;">
          <el-input v-model="ruleForm.merchantInfo.shopName"></el-input>
        </el-form-item>
        <el-form-item label="真实姓名:" prop="storeType" style="width: 50%;">
          <el-input v-model="ruleForm.merchantInfo.name"></el-input>
        </el-form-item>
        <el-form-item label="身份证:" prop="storeType" style="width: 50%;">
          <el-input v-model="ruleForm.merchantInfo.idCard"></el-input>
        </el-form-item>

        <el-form-item label="门店地址:" prop="detailedAddress" style="width: 50%;">
          <el-input type="textarea" v-model="ruleForm.merchantInfo.address"></el-input>
        </el-form-item>

        <el-form-item label="详细地址:" prop="detailedAddress" style="width: 50%;">
          <el-input type="textarea" v-model="ruleForm.merchantInfo.detailAddress"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click.prevent="updateForm" style="width: 150px;line-height: 15px;">修改
          </el-button>
        </el-form-item>
      </el-form>
    </el-main>
  </el-container>

</template>

<script>
//省市区
import {pcaTextArr} from "element-china-area-data";
import axios from "axios";

export default {
  name: 'ziLiAoWeiHu',
  components: {},
  data() {
    return {
      isCollapse: false,
      imageUrl: '',
      ary:'',
      pcaTextArr, //地址数据
      selectedOptions: [], //地址绑定,必须是数组
      ruleForm: {
        merchantInfo:{
          phone:'',
        },
      },


    }
  },
  methods: {

    async updateForm() {
      await axios.post(`/merchantInfo/updById`, this.ruleForm.merchantInfo);
      this.$message.success("修改成功");
    },
    //拿到id
    async ruleForms() {
      //拿用户id
      this.sysUsersId=this.$store.state.user.sysUsersId
      console.log('sysUsersId-------------',this.sysUsersId)
      const {data: res} = await this.$http.post(`/merchantInfo/selBySysId/${this.sysUsersId}`)
      this.ruleForm.merchantInfo=res[0];
      console.log(res)
    },

    // 图片上传
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },
    //级联地区改变
    handleChangeAddress(value) {
      console.log(value.this.ruleForm().address);
    },

  },
  created() {
    this.ruleForms();
    let temp = this.ary.split('-')
    console.log('ary', temp);
    this.selectedOptions = temp

  },

}

</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 130px;
  height: 130px;
  line-height: 130px;
  text-align: center;
}

.avatar {
  width: 130px;
  height: 130px;
  display: block;
}
</style>